#include <iostream>
using namespace std;

class Rect
{
public:
    Rect(int w, int h) : w(w), h(h) {}

    Rect operator+(Rect &other)
    {
        return Rect(this->w + other.w, this->h + other.h);
    }

    Rect operator+(int n)
    {
        return Rect(this->w + n, this->h + n);
    }

    Rect operator-(Rect &other)
    {
        return Rect(this->w - other.w, this->h - other.h);
    }

    Rect operator-(int n)
    {
        return Rect(this->w - n, this->h - n);
    }

    friend Rect operator+(int n, Rect &other);
    friend Rect operator-(int n, Rect &other);

    void print()
    {
        cout << "w: " << w << ", h: " << h << endl;
    }

private:
    int w;
    int h;
};

Rect operator+(int n, Rect &other)
{
    return Rect(other.w + n, other.h + n);
}

Rect operator-(int n, Rect &other)
{
    return Rect(other.w - n, other.h - n);
}

int main()
{
    Rect r1(10, 20);
    Rect r2(30, 40);
    Rect r3(50, 60);

    Rect r4 = 9 + r1 + 5 + r2 + 6 + r3 - 7;
    r4.print();
}
